/*
 * File Name: StatusBar.java
 * Created on: November 13 2007, 02:43 PM
 */

package co.edu.uniandes.intercon.client.gui;

import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;

import co.edu.uniandes.intercon.client.model.StatusBarMessage;

/**
 * Panel used to contain the status messages prompted by the application
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class StatusBarPanel extends AbstractBasePanel implements Observer {
    
    /**
     * Label containing the message
     */
    private JLabel label;
    
    /**
     * Creates a new panel and register itself as a observer of 
     * {@link StatusBarMessage}
     */
    public StatusBarPanel() {
        initGUI();
        StatusBarMessage.getInstance().addObserver(this);
    }
    
    /*
     * Init gui 
     */
    private void initGUI() {
        setLayout(new BorderLayout());
        label = new JLabel(" ");
        add(label, BorderLayout.CENTER);
    }
    
    /**
     * Reflects changes in the status bar component. It automatically hides 
     * itself when the <code>arg</code> parameter is set to 
     * {@link suncertify.gui.util.StatusBarMessage#UPDATE_MODE_HIDE}. Otherwise it just shows the
     * message specified. 
     * 
     * @see Observer#update(Observable, Object)
     */    
    public void update(Observable o, Object arg) {
        if (StatusBarMessage.UPDATE_MODE_MESSAGE.equals(arg)) {
            label.setText(StatusBarMessage.getInstance().getMessage());
        } else {
            if (StatusBarMessage.UPDATE_MODE_HIDE.equals(arg)) {
                super.setVisible(StatusBarMessage.getInstance().isHidden());
            }
        }
    }
    
}
